const state = {
  dictTemplate: new Array()
}
const mutations = {
  SET_DICT_TEMPLATE: (state, { key, value }) => {
    if (key !== null && key !== '') {
      state.dictTemplate.push({
        key: key,
        value: value
      })
    }
  },
  REMOVE_DICT_TEMPLATE: (state, key) => {
    try {
      for (let i = 0; i < state.dictTemplate.length; i++) {
        if (state.dictTemplate[i].key == key) {
          state.dictTemplate.splice(i, i)
          return true
        }
      }
    } catch (e) {}
  },
  CLEAN_DICT_TEMPLATE: state => {
    state.dictTemplate = new Array()
  }
}

const actions = {
  // 设置字典
  setDictTemplate({ commit }, data) {
    commit('SET_DICT_TEMPLATE', data)
  },
  // 删除字典
  removeDictTemplate({ commit }, key) {
    commit('REMOVE_DICT_TEMPLATE', key)
  },
  // 清空字典
  cleanDictTemplate({ commit }) {
    commit('CLEAN_DICT_TEMPLATE')
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
